const axios = require("axios")  //ajax请求
const iconv = require("iconv-lite")  // 解码
const cheerio = require("cheerio")  // dom

class utils {

    async get(url, type = "") {
      let re =  (await axios.get(
            url,{responseType:'arraybuffer'})).data;  
            //iconv.decode(re,"gbk")  数据转化成gbk格式
            let data= cheerio.load(iconv.decode(re,"gbk"))
            return type == "" ? data : re;
            
    }
    // iconv-lite 需要npm i iconv-lite
   // iconv.decode(值, 要转的编码)  iconv.encode()
     
}

module.exports = new utils()